package net.alche.fa.core.doing.invoker;

import net.alche.fa.core.doing.FaAnnoDoing;
import net.alche.fa.core.model.FaValue;
import java.util.List;
import cn.hutool.core.thread.ThreadUtil;
import net.alche.fa.core.FaException;
import java.lang.Runnable;
import net.alche.al.util.AC;

// ThreadUtilInvoker
@FaAnnoDoing
@SuppressWarnings("all") 
public class ThreadUtilInvoker extends AbstractObjectInvoker {

  public ThreadUtilInvoker() {}

  // 是否为此对象
  public boolean matched(FaValue objVal, Object obj, String methodName, List<FaValue> params) {
    if ( obj instanceof ThreadUtil) {
      return true;
    }
    return false;
  }

  // 调用
  public FaValue invoke(FaValue objVal, Object obj, String methodName, List<FaValue> params) throws FaException {
    ThreadUtil util = (ThreadUtil)obj;
    FaValue first = null;
    if ( params != null && !params.isEmpty()) {
      first = params.get(0);
    }
    switch ( methodName) {
      case "execAsync" : {
        Runnable run = (Runnable)first.getValue();
        return new FaValue(util.execAsync(run));
      }
      default : {
        throw new FaException(FaException.LESS_METHOD, "fa-invoke ThreadUtil method not find | method = " + methodName, "params=" + AC.json.toStr(params));
      }
    }
  }
}